<?php

namespace App\Http\Controllers;

use App\Models\Reply;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\ReplyRequest;
use Illuminate\Support\Facades\Auth;

class RepliesController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth', ['except' => ['index', 'show']]);
    }
	public function store(ReplyRequest $request , Reply $reply)
	{
        $content = clean($request->get('content'));
	    if(!empty($content)) {
            $reply->content = $request->input('content');
            $reply->user_id = Auth::user()->id;
            $reply->topic_id = $request->topic_id;
            $reply->save();
        }else{
	        return back()->with('error','想攻击爸爸？');
        }
        return redirect()->to($reply->topic->link())->with('success', '创建成功！');
	}
	public function destroy(Reply $reply)
	{
		$this->authorize('destroy', $reply);
		$reply->delete();

		return redirect()->to($reply->topic->link())->with('success', 'Deleted successfully.');
	}
}